<?php
/**
 * Created by PhpStorm.
 * User: W
 * Date: 2018/12/28
 * Time: 10:51
 */

namespace app\sports_admin\model;


use think\Model;
use think\Request;

class TrainComment extends Model
{
    protected $table = "train_comment";
    protected $pk    = "id";
    public static function trainList($page,$rows,$sort,$sortOrder,$searchName,$trainId)
    {
        $adminList = self::where(function($query)use($searchName){
            if($searchName){
                $query->where('name','like',"%{$searchName}%");
            }})
            ->where('train_id',$trainId)
            ->page($page)
            ->limit($rows)
            ->order("{$sort}","{$sortOrder}")->select();

        $adminCount = self::where(function($query)use($searchName){
            if($searchName){
                $query->where('name','like',"%{$searchName}%");
            }})
            ->where('train_id',$trainId)
            ->count();
        return ['rows'=>$adminList,'total'=>$adminCount];
    }
    //添加培训机构评论
    public static function trainCommentAdd()
    {
        $data = Request::instance()->only("id,name,content,image,score");
        $create_time = time();
        $update_time = time();
        $parents_image = "";
        return self::insert(["train_id"=>$data['id'],"name"=>$data['name'],"content"=>$data['content'],"score"=>$data['score'],"image"=>$data['image'],"create_time"=>$create_time,"update_time"=>$update_time]);
    }

}